<?php
namespace Tbf\Crypto\Password\Plan;
use Tbf\Crypto\Password\PlanInterface;
use Tbf\Util\StringUtil;
use Tbf\Error\CryptoException;
/**
* ecshop 用户密码方案
* 加密后的密码格式
* 原文a123456 加密后 $ecshop$3959$04affd4751ad4b43cb2c4c06342de454
* 不要用这个方案加密密码...(不安全)
 * @deprecated
*/
class EcshopPlan implements PlanInterface{
	function hash($plain){
		$salt = mt_rand(0,9999);
		$encrypted = md5(md5($plain).$salt);
		return '$ecshop$'.$salt.'$'.$encrypted;
	}
	function verify($plain,$hashed){
		$data = explode('$',$hashed);
		$salt = $data[2];
		$hashed_encrypted = $data[3];
		$plain_encrypted = md5(md5($plain).$salt);
		return $hashed_encrypted==$plain_encrypted;
	}
	function support($hashed){
		if (!StringUtil::startWith($hashed,'$ecshop$')){
			return false;
		}
		return true;
	}
}